package com.sky.controller.admin;

import com.sky.annotation.Permission;
import com.sky.dto.DishDTO;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.mapper.SetmealMapper;
import com.sky.result.PageBean;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
@Slf4j
public class SetmealController {
    @Autowired
    SetmealService setmealService;

    /**
     * 套餐的分页展示
     *
     * @return
     */
    @GetMapping("/page")
    public Result<PageBean<SetmealVO>> selectByPage(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("套餐的分页查询{}", setmealPageQueryDTO);
        PageBean<SetmealVO> pageBean = setmealService.selectByPage(setmealPageQueryDTO);
        return Result.success(pageBean);
    }

    /**
     * 根据id查询套餐
     */
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Long id) {
        log.info("根据id查套餐{}", id);
        SetmealVO setmealVO = setmealService.selectById(id);
        return Result.success(setmealVO);
    }
    /**
     * 新增一个套餐
     */
    @PostMapping
    @Permission(Value = "insert")
    public Result add(@RequestBody SetmealDTO setmealDTO){
         log.info("新增一个套餐{}",setmealDTO );
         setmealService.add(setmealDTO);
         return Result.success();
    }

    /**
     * 修改套餐
     */
    @PutMapping
    public Result update(@RequestBody SetmealDTO dto){
        log.info("更新套餐{}", dto);
        setmealService.update(dto);
        return Result.success();
    }
    /**
     * 删除一个套餐
     */
    @DeleteMapping
    public Result delete(@RequestParam("ids") List<Long> ids){
        log.info("删除套餐{}", ids);
        setmealService.delete(ids);
        return Result.success();

    }
    /**
     * 更新套餐状态
     */
    @PostMapping("/status/{status}")
    public Result changeStatus(@PathVariable Integer status,@RequestParam Long id){
        log.info("更改套餐状态{}，ID：{}", status,id);
        setmealService.changeStatus(status,id);
        return Result.success();
    }




}